package 笔试记录.M8day31广联达;

import java.util.*;
public class Solution1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr1 = new int[n];//发射顺序
        int[] arr2 = new int[n];//到达顺序

        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = sc.nextInt();
        }
        for (int i = 0; i < arr2.length; i++) {
            arr2[i] = sc.nextInt();
        }

        boolean[] flag = new boolean[n + 1];
        int count = 0;//记录数量
        int index = 0;//记录下标
        for(int i = 0;i < n;++i){
            if(!flag[arr1[i]]){
                for(;index < n && arr2[index] != arr1[i];++index){
                    count++;
                    flag[arr2[index]] = true;
                }
                //跳过当前
                index++;
            }
        }
        System.out.println();
        System.out.println(count);
    }
}
